require("../css/register.less")

document.ready(function(){
    let myaccount=document.querySelector("#myaccount")
    let mymm=document.querySelector("#mymm")
    let btn1=document.querySelector("#btn1")
   
    btn1.addEventListener("click",function(){
        let account=myaccount.value
        let mm=mymm.value
        if(!window.$utils.isPhone(account)){
            tips.textContent="请输入正确的账号"
        }else if(!window.$utils.isPassword(mm)){
            tips.textContent="请输入6-12位的字母数字下划线"
        }else{
            tips.textContent=""
            axios.post("http://139.9.177.51:8099/users/login",
            {
                "account":account,
                "password":mm
            }
            ).then(function(res){
                let ret=res.data
                console.log(ret);
                if(ret.status===0){
                    // window.$utils.toast("duigou","登录成功")
                    window.$utils.toast()
                    window.setTimeout(function(){
                        window.location.href="./index.html"
                    },3000)
                    //把个人信息保存到本地存储中
                    window.localStorage.setItem("user",JSON.stringify(ret.data.user))
                }else if(ret.status===555){
                    window.$utils.toast("cuowu","登录失败!")
                }
            }).catch(function(err){
                console.log(err);
            })
       
        }
    })
})